home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Form / Sources / EditCmd.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.8 KB  |  187 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EditCmd.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef EDITCMD_H
  11. #define EDITCMD_H
  12.  
  13. //----------------------------------------------------------------------------------------
  14. // Imported Classes
  15. //----------------------------------------------------------------------------------------
  16.  
  17. #ifndef FWCLPCMD_H
  18. #include "FWClpCmd.h"
  19. #endif
  20.  
  21. #ifndef FWCONTNT_H
  22. #include "FWContnt.h"
  23. #endif
  24.  
  25. #ifndef FWSELECT_H
  26. #include "FWSelect.h"
  27. #endif
  28.  
  29. //========================================================================================
  30. //    Forward Declaration
  31. //========================================================================================
  32.  
  33. class FW_CEditView;
  34. class FW_CFrame;
  35. class CEditViewSelection;
  36.  
  37. //========================================================================================
  38. //    class CEditViewCommand
  39. //========================================================================================
  40.  
  41. class CEditViewCommand : public FW_CClipboardCommand, public FW_MReceiver
  42. {
  43.   public:
  44.     FW_DECLARE_AUTO(CEditViewCommand)
  45.  
  46.     CEditViewCommand(Environment* ev, 
  47.                          ODCommandID commandID,
  48.                          FW_CFrame* frame, 
  49.                          FW_Boolean canUndo);
  50.  
  51.     virtual ~ CEditViewCommand();
  52.  
  53.     // ----- FW_CCommand API -----
  54.     virtual void         UndoIt(Environment* ev);
  55.     virtual void         RedoIt(Environment* ev);
  56.     virtual void         SaveUndoState(Environment* ev);
  57.     virtual void         SaveRedoState(Environment* ev);
  58.  
  59.     // ----- FW_CClipboardCommand API -----
  60.     virtual void        PreCommand(Environment* ev);
  61. //    virtual void         CommandDone(Environment* ev);
  62.  
  63.     // ----- FW_MReceiver API -----
  64.     void                 HandleNotification(Environment* ev, const FW_CNotification& notification);
  65.  
  66.     // ----- New API
  67.     void                 SetEditView(FW_CEditView* editView);
  68.     void                 SetSelection(CEditViewSelection* selection);
  69.     CEditViewSelection* GetSelection(Environment* ev) const;
  70.     
  71.   private:
  72.     void                 RemoveText(Environment* ev);
  73.     void                 RestoreText(Environment* ev);
  74.     void                 RemoveAndRestoreText(Environment* ev, FW_ByteCount bytesToRemove, 
  75.                             const FW_CString& textToRestore);
  76.  
  77.   private:
  78.     FW_Boolean            fOwnsSelection;    
  79.     FW_CEditView*        fEditView;
  80.     //--- Saved data for undo/redo
  81.     FW_CString            fPastedText;
  82.     FW_CString            fSavedText;        // original text (Paste command)
  83.     short                fStartOffset;
  84.     short                fEndOffset;
  85. };
  86.  
  87. //========================================================================================
  88. //    class CEditViewSelContent
  89. //========================================================================================
  90.  
  91. class CEditViewSelContent : public FW_CContent
  92. {
  93.   public:
  94.     FW_DECLARE_AUTO(CEditViewSelContent)
  95.     
  96.     CEditViewSelContent(Environment* ev, FW_CEditView* editview);
  97.     virtual ~CEditViewSelContent();
  98.  
  99.   public:
  100.     //------ FW_CContent API
  101.     virtual void        Externalize(Environment* ev,
  102.                                     ODStorageUnit* storageUnit,
  103.                                     FW_EStorageKinds storageKind,
  104.                                     FW_CCloneInfo* cloneInfo);
  105.     virtual FW_Boolean    Internalize(Environment* ev,
  106.                                     ODStorageUnit* storageUnit, 
  107.                                     FW_EStorageKinds storageKind,
  108.                                     FW_CCloneInfo* cloneInfo);
  109.  
  110.     //------ New API
  111.     FW_CString             GetInternalizedText(Environment* ev);
  112.     void                 ClearSelectedText(Environment* ev);
  113.     void                 UnselectText(Environment* ev);
  114.     FW_Boolean             IsEmpty(Environment* ev) const;
  115.  
  116.   protected:
  117.     FW_CEditView*         fEditView;
  118.     FW_CString            fInternalizedText;    // holds text that was just internalized
  119. };
  120.  
  121. //----------------------------------------------------------------------------------------
  122. inline FW_CString CEditViewSelContent::GetInternalizedText(Environment*)
  123. {
  124.     return fInternalizedText;
  125. }
  126.  
  127. //========================================================================================
  128. //    class CEditViewSelection
  129. //========================================================================================
  130.  
  131. class CEditViewSelection : public FW_CSelection
  132. {
  133.   public:
  134.     FW_DECLARE_AUTO(CEditViewSelection)
  135.  
  136.     CEditViewSelection(Environment* ev, FW_CEditView* editview);
  137.     virtual ~CEditViewSelection();
  138.     
  139.   public:
  140.     virtual void            CloseSelection(Environment* ev);
  141.     virtual void            ClearSelection(Environment* ev);
  142.     virtual FW_Boolean        IsEmpty(Environment* ev) const;
  143.     virtual void            SelectAll(Environment* ev);
  144.  
  145.     virtual FW_CContent*    GetSelectedContent(Environment* ev);
  146.  
  147.   private:
  148.     CEditViewSelContent*    fSelectedContent;
  149. };
  150.  
  151. //========================================================================================
  152. // Prototypes
  153. //========================================================================================
  154.  
  155. FW_Boolean InternalizeText(Environment* ev, ODStorageUnit* storageUnit, 
  156.                                 FW_CString& textData, FW_ByteCount maxChars);
  157.  
  158. //========================================================================================
  159. //     Inlines
  160. //========================================================================================
  161.  
  162. //---------------------------------------------------------------------------------------------------
  163. //     CEditViewCommand
  164. //---------------------------------------------------------------------------------------------------
  165.  
  166. inline void CEditViewCommand::SetSelection(CEditViewSelection* selection)
  167. {
  168.     fSelection = selection;
  169.     fOwnsSelection = true;    // we can delete our own selection later
  170. }
  171.  
  172. inline CEditViewSelection* CEditViewCommand::GetSelection(Environment*) const
  173. {
  174.     return (CEditViewSelection*)fSelection;
  175. }
  176.  
  177. //---------------------------------------------------------------------------------------------------
  178. //     CEditViewSelection
  179. //---------------------------------------------------------------------------------------------------
  180.  
  181. inline FW_CContent* CEditViewSelection::GetSelectedContent(Environment*)
  182. {
  183.     return fSelectedContent;
  184. }
  185.  
  186. #endif
  187.